package hander

import (
	"chat/api/request"
	"chat/internal/dao"
	"chat/internal/model"
	"chat/pkg"
	"github.com/gin-gonic/gin"
	"net/http"
)

func SelectMsg(c *gin.Context) {
	var req request.SelectReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"msg":  "验证失败",
			"code": 500,
			"data": err.Error(),
		})
		return
	}
	dan := pkg.Dan(req.Message)
	c.JSON(http.StatusOK, gin.H{
		"msg":  "OK",
		"code": 200,
		"data": dan,
	})
}

func Add(c *gin.Context) {
	var req request.AddReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"msg":  "验证失败",
			"code": 500,
			"data": err.Error(),
		})
		return
	}
	m := model.Message{
		Message: req.Message,
		Num:     req.Num,
	}
	dan := pkg.Dan(req.Message)
	if dan == "合规" {
		dao.Create(&m)
	}
	c.JSON(http.StatusOK, gin.H{
		"msg":  "OK",
		"code": 200,
		"data": "Add",
	})
}
